<?php
session_start();
require_once("database.php");
$conn=mysql_link();
$name=$_SESSION['username'];
//echo $name;
$us=$_SESSION['email'];
$cha="SELECT * FROM users where Email='$us'";
$sql2= mysqli_query($conn,$cha);
$res2= mysqli_fetch_assoc($sql2);
$username = $res2["Name"];

$sql="SELECT * FROM borrowrecords where re=1 ";
$sql1= mysqli_query($conn,$sql);
$res=mysqli_fetch_all($sql1,MYSQLI_ASSOC);

//测试session是否可以正常读取
//echo($username);

if ($_GET["action"]=="jieyue"){
//    print_r($res);
    $Number=$_POST['Number'];
    $bookName=$_POST['bookName'];
    $user=$_POST['user'];
    if (empty($Number and $bookName and $user)){
        echo "<script> alert('请填写完整信息')</script>";
    }else{
        $mysql="SELECT * FROM borrowrecords where UserID='$username'";
        $sql1= mysqli_query($conn,$mysql);
        $res1= $sql1->num_rows;
        if ($res1 > 0){
            $UPDATE="UPDATE borrowrecords SET re = 2 WHERE Bookname='$bookName';";
            $UPDATE1= mysqli_query($conn,$UPDATE);
            echo "<script> alert('成功')</script>";
        }else{
            echo "<script> alert('请填写正确信息')</script>";
            echo "<script> location.href = 'return.php'</script>";
            die();
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/BookReturn.css">
    <link href="https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css" rel="stylesheet" />

</head>
<body>
    <div class="all">
        <!-- 左手边菜单栏 -->
        <div class="h left_Menu_Bar Center">
            <div class="Menu_Bar Center">
                <!-- 头像 -->
                <div class="avatar">
                    <!-- 默认头像 -->
                    <h1 class="avatar_tou">管</h1>
                </div>
                <!-- 菜单 -->
                <div class="Menu Font">
                    <ul class="Center ct">
                        <li><a href="#">用户管理</a></li>
                        <li><a href="#">图书管理</a></li>
                        <li>
                            <a href="#">借阅管理</a> <button class="btn" id="btn"><i class="bx bx-chevron-down"
                                    id="arrow"></i></button>
                        </li>
                    </ul>
                </div>
            </div>
                   <!-- 下拉菜单 -->
                   <div class="box " id="dropdown">
                    <ul class="drop_down_menu Center">
                      <li><a href="./BorrowBooks.html">借阅</a></li>
                      <li><a href="BookReturn.php">归还</a> </li>
                      <li><a href="BorrowingRecord.php">记录</a> </li>
                        <!-- <li><a href="#">过期</a></li> -->
                    </ul>
                </div>
                <div  class="client"><button class="client_btn"></button>客户端</div>
        </div>

    <div class="borrow-return">
        <h1 class="title">图书归还</h1>
        <form action="?action=jieyue" id="form" method="post">
        <div class="book-information">
            条形码<input  name="Number" type="text" class="Number">
            书籍<input  name="bookName" type="text" class="bookName">
            用户名<input name="user" type="text" class="bookName" >
        </div>
        <div class="button">
            <div style="display: flex;">
<!--                修改成button-->
<!--                你的form表单呢？-->
<!--              <div class="sure"><a href="">确定</a></div>-->
<!--              <div class="cancel"><a href="">取消</a></div>-->
                <button class="sure" name="button">确认</button>
                <button class="cancel">取消</button>
            </div>
        </div>
        <div class="Information">
            <ul class="blue">
              <li>索书名</li>
              <li>条形码</li>
              <li>书籍</li>
              <li>文献所属地</li>
              <li>借阅地点</li>
              <li>应还时间</li>
            </ul>
            <?foreach ($res as $value){?>
            <ul class="blue">
             <li><?echo $value['RecordID']?></li>
             <li><?echo $value['BookID']?></li>
             <li><?echo $value['Bookname']?></li>
             <li><?echo $value['di']?></li>
             <li><?echo $value['BorrowDate']?></li>
             <li><?echo $value['ReturnDate']?></li>
            </ul>
<?}?>
            <p>没有更多咯~</p>
        </div>
        </form>
    </div>
    </div>

    <script src="../js/BookReturn.js"></script>
</body>
</html>